import EventCenter from "../../TFrame/script/helper/EventCenter";
import EventNames from "../EventNames";
import { ActionType } from "../net/Enum";
import ServiceLogic from "../net/ServerLogic";
import CoinSystem from "../system/CoinSystem";
import GardenSystem from "./GardenSystem";

const { ccclass, property } = cc._decorator;

@ccclass
export default class CoinFruit extends cc.Component {

    @property(cc.Label)
    coinText: cc.Label = null;

    coin: number = 0;
    flowerIdx: number = 0;
    start() {
        //此处要求果子命名为花的下标s
        this.flowerIdx = parseInt(this.node.name)
        this.coin = GardenSystem.getProduceCoin(this.flowerIdx)
        this.coinText.string = this.coin.toString();
    }

    click() {
        EventCenter.emit(EventNames.FlyGetCoinEvent, this.coin, this.node.convertToWorldSpaceAR(cc.Vec2.ZERO));
        CoinSystem.addCoin(this.coin);

        EventCenter.emit(EventNames.PlantCoinCollected, this.flowerIdx)

        ServiceLogic.action(ActionType.ActionCollectCoin, { "beiz": "花" + this.flowerIdx + "收" + this.coin, "coinhave": CoinSystem.coinInMomory })
        this.node.destroy();
    }
}
